<%@page import="java.util.Calendar"%>
<%@page import="java.util.Date"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>新增预约</title>
<style>
body {
	font-family: "Lucida Grande", Helvetica, Arial, Verdana, sans-serif;
	font-size: 14px;
}

button, input {
	border: 1px solid #999;
	padding: 5px 5px;
	/* margin: 0 10px 10px 0; */
}

button {
	cursor: pointer;
}
</style>
<link rel="stylesheet" type="text/css"
	href="${ pageContext.request.contextPath }/resources/script/jquery.datetimepicker.css">
<script type="text/javascript"
	src="${pageContext.request.contextPath }/resources/script/fullcalendar-3.0.1/lib/jquery.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath }/resources/script/layer/layer.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath }/resources/script/jquery.datetimepicker.full.js"></script>
<script type='text/javascript' src='${pageContext.request.contextPath }/dwr/engine.js'></script>
<script type='text/javascript'
	src='${pageContext.request.contextPath }/dwr/interface/meetingRoomBookingService.js'></script>
<script type='text/javascript' src='${pageContext.request.contextPath }/dwr/util.js'></script>
<script type="text/javascript">
	//为按钮添加点击时间
	$(document).ready(
			function() {
				var index = parent.layer.getFrameIndex(window.name);
				$.datetimepicker.setLocale('ch');
				$('#datetimepicker1,#datetimepicker2').datetimepicker({
					step : 30,
					format : "Y-m-d H:i",
					timeFormat : "H:m:s"
				});
				$('#closeIframe').click(
				//parent父页操作之添加记录
				function() {
					parent.layer.close(index);
				});
				$('#addBooking').click(
						function() {
							var roomId = $('#roomId').val();
							var cname = $('#cname').val();
							var startstr = $('#datetimepicker1').val();
							var endstr = $('#datetimepicker2').val();
							var username = $('#username').val();
							var phone = $('#phone').val();
							if (startstr > endstr) {
								layer.msg('开始时间必须小于结束时间！');
							} else {
								meetingRoomBookingService.addBooking(roomId,
										cname, startstr, endstr, username,
										phone, addResult);
								layer.load(1, {
									shade : false
								});
							}
							/* layer.msg(cname + " " + startstr + " " + endstr + " " + username + " " + phone); */
						});
			});
	function addResult(result) {
		layer.closeAll('loading');//关闭加载层
		var strarray = result.split(",");
		if (strarray[0] != "Y") {
			layer.msg(strarray[0]);
		} else {
			var eventData = {
				id : strarray[1],
				title : $('#cname').val(),
				start : $('#datetimepicker1').val(),
				end : $('#datetimepicker2').val()
			};
			parent.$('#calendar').fullCalendar('renderEvent', eventData, true);
			document.write(strarray[2]);
		}
	};
</script>
</head>
<body>
	<div>
		<!-- <button id="closeIframe">关闭</button> -->
		<%-- <s:debug /> --%>
		<%-- <s:property value="#parameters['currentDate']" /> --%>
		<%
			// Long字符串转换成日期字符串
			/* out.print(request.getParameter("currentDate")); */
			String datestr = request.getParameter("currentDate");
			SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm");
			Long long1 = Long.parseLong(datestr);
			Date date = new Date(long1);
			Calendar calendar = Calendar.getInstance();
			calendar.setTime(date);
			calendar.add(Calendar.MINUTE, 30);
			Date date2 = calendar.getTime();
			//out.print(format.format(date));
		%>
	</div>
	<div style="margin-left: 5px">
		<form >
			<input id="roomId" type="text" name="roomId" style="display: none"
				value="<%=request.getParameter("roomId")%>">
			<table style="border-collapse: separate; border-spacing: 0px 30px;">
				<tr>
					<td><label
						style="vertical-align: middle; display: inline-block">会议名称:</label>
					</td>
					<td colspan="3"><input id="cname" type="text"
						style="width: 200px" name="booking.name"></td>
				</tr>
				<!-- <tr>
					<td>&nbsp;</td>
					<td>&nbsp;</td>
					<td>&nbsp;</td>
					<td>&nbsp;</td>
				</tr> -->
				<tr>
					<td><label
						style="vertical-align: middle; display: inline-block">开始时间:</label>
					</td>
					<td><input id="datetimepicker1" type="text"
						style="vertical-align: middle; width: 110px"
						value='<%=(format.format(date))%>' name="booking.bookingTimestr"></td>
					<td><label
						style="vertical-align: middle; display: inline-block">&nbsp;结束时间:</label>
					</td>
					<td><input id="datetimepicker2" type="text"
						style="vertical-align: middle; width: 110px"
						value='<%=(format.format(date2))%>' name="booking.endTimestr"></td>
				</tr>
				<!-- <tr>
					<td>&nbsp;</td>
					<td>&nbsp;</td>
					<td>&nbsp;</td>
					<td>&nbsp;</td>
				</tr> -->
				<tr>
					<td><label>预约人:</label></td>
					<td><input id="username" type="text" style="width: 110px"
						name="booking.userName" /></td>
					<td><label>&nbsp;电话:</label></td>
					<td><input id="phone" type="text" style="width: 110px"
						name="booking.phone" /></td>
				</tr>
				<tr>
					<td>&nbsp;</td>
					<td>&nbsp;</td>
					<td>&nbsp;</td>
					<td>&nbsp;</td>
				</tr>
				<tr style="margin-top: 20px">
					<td colspan="2" align="center" rowspan="3"
						style="vertical-align: middle;"><input id="addBooking"
						type="button" style="width: 80px" value="提交"></td>
					<td colspan="2" align="center" rowspan="3"
						style="vertical-align: middle;"><button id="closeIframe" type="button"
							style="width: 80px">关闭</button></td>
				</tr>
			</table>

		</form>
	</div>
</body>
</html>